#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;

int n, q, a[N];

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    cin >> q;
    while(q --)
    {
        int x, y; cin >> x >> y;
        int l = 1, r = n;
        while(l < r)
        {
            int mid = l + r >> 1;
            if(a[mid] >= x) r = mid;
            else l = mid + 1;
        }
        if(a[l] < x) cout << 0 << endl;
        else
        {
            int b = l;
            l = 1, r = n;
            while(l < r)
            {
                int mid = l + r + 1 >> 1;
                if(a[mid] <= y) l = mid;
                else r = mid - 1;
            }
            if(a[l] > y) cout << 0 << endl;
            else cout << l - b + 1 << endl;
        }
    }
    return 0;
}